<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="css/app.css" />
		<style>
			.title {
				margin: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
			}
			
			.oa-contact-cell.mui-table .mui-table-cell {
				padding: 11px 0;
				vertical-align: middle;
			}
			
			.oa-contact-cell {
				position: relative;
				margin: -11px 0;
			}
			
			.oa-contact-avatar {
				width: 75px;
			}
			
			.oa-contact-avatar img {
				border-radius: 50%;
			}
			
			.oa-contact-content {
				width: 100%;
			}
			
			.oa-contact-name {
				margin-right: 20px;
			}
			
			.oa-contact-name,
			oa-contact-position {
				float: left;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">报警</h1>
		</header>
		<nav class="mui-bar mui-bar-tab">
			<a class="mui-tab-item mui-active" id="bj">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">报警</span>
			</a>
			<a class="mui-tab-item" id="bk">
				<span class="mui-icon mui-icon-email"></span>
				<span class="mui-tab-label">布控</span>
			</a>
			<a class="mui-tab-item" id="wd">
				<span class="mui-icon mui-icon-gear"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>
		<div class="mui-content">
			<div class="mui-control-content mui-active">
				<div style="padding: 10px 10px;">
					<div id="segmentedControl" class="mui-segmented-control">
						<a class="mui-control-item mui-active" href="#item1">
							未读(<span id="wdsl">0</span>)
						</a>
						<a class="mui-control-item" href="#item2">
							已读(<span id="ydsl">0</span>)
						</a>
					</div>
				</div>
				<div id="item1" class="mui-control-content mui-active" style="height:28em;">
					<div id="scroll" class="mui-scroll-wrapper">
						<div class="mui-scroll">
							<ul class="mui-table-view" id="weidu">
							</ul>
						</div>
					</div>
				</div>
				<div id="item2" class="mui-control-content" style="height:28em;">
					<div id="scroll" class="mui-scroll-wrapper">
						<div class="mui-scroll">
							<ul class="mui-table-view" id="yidu">
							</ul>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script src="js/mui.min.js"></script>
	<script src="js/jquery.min.js"></script>
	<script src="js/config.js"></script>
	<script>
		mui.init({
			swipeBack: true
		});
		mui('#scroll').scroll({
			indicators: true //是否显示滚动条
		});
		$(function() {
			$("#bk").on("tap", function() {
				mui.openWindow({
					url: "dc.html",
					id: "dc",
					createNew: true,
					show: {
						aniShow: "none"
					}
				});
				$(".mui-bar-tab a").removeClass("mui-active");
				$("#bj").addClass("mui-active");
				return false;
			});
			$("#bj").on("tap", function() {
				mui.openWindow({
					url: "index.html",
					id: "bj",
					createNew: true,
					show: {
						aniShow: "none"
					}
				});
				$(".mui-bar-tab a").removeClass("mui-active");
				$("#bj").addClass("mui-active");
				return false;
			});
			$("#wd").on("tap", function() {
				mui.openWindow({
					url: "setting.html",
					id: "wd",
					createNew: true,
					show: {
						aniShow: "none"
					}
				});
				$(".mui-bar-tab a").removeClass("mui-active");
				$("#bj").addClass("mui-active");
				return false;
			});

			function weidufun() {
				$.get(dataDomain + "/dc/alarms?isRead=0", function(req) {
					if(req.data.length > 0) {
						$("#wdsl").html(req.data.length);
						var yidu = $("#weidu");
						var htm = '';
						for(var i = 0; i < req.data.length; i++) {
							htm += '<li class="mui-table-view-cell">';
							htm += '<p>姓名：' + req.data[i].realName + '&nbsp;&nbsp;&nbsp;&nbsp;证件类型：' + req.data[i].cardType + '<button myid="' + req.data[i].id + '" type="button" style="padding:0;float:right;" class="mui-btn-link ydbtn">已读</button></p>';
							htm += '<p>证件号码：' + req.data[i].cardNo + '</p>';
							htm += '<p>离港时间：' + req.data[i].leaveTime + '</p>';
							htm += '<p>' + req.data[i].startAndEnd + '&nbsp;&nbsp;&nbsp;&nbsp;班次：' + req.data[i].number + '&nbsp;&nbsp;&nbsp;&nbsp;舱位:' + req.data[i].space + '</p>';
							htm += '<p>购票时间:' + req.data[i].buyTime + '</p>';
							htm += '</li>';
						}
						yidu.html(htm);
						$(".ydbtn").on("tap", function() {
							var myid = $(this).attr("myid");
							$.ajax({
								type: "PUT",
								url: dataDomain + "/dc/alarm/read",
								data: {
									id: myid
								},
								async: true,
								success: function(req) {
									if(req.status == 'ok') {
										weidufun();
										yidufun();
									}
								}
							});
						});
					}
				});
			}

			function yidufun() {
				$.get(dataDomain + "/dc/alarms?isRead=1", function(req) {
					if(req.data.length > 0) {
						$("#ydsl").html(req.data.length);
						var yidu = $("#yidu");
						var htm = '';
						for(var i = 0; i < req.data.length; i++) {
							htm += '<li class="mui-table-view-cell">';
							htm += '<p>姓名：' + req.data[i].realName + '&nbsp;&nbsp;&nbsp;&nbsp;证件类型：' + req.data[i].cardType + '</p>';
							htm += '<p>证件号码：' + req.data[i].cardNo + '</p>';
							htm += '<p>离港时间：' + req.data[i].leaveTime + '</p>';
							htm += '<p>' + req.data[i].startAndEnd + '&nbsp;&nbsp;&nbsp;&nbsp;班次：' + req.data[i].number + '&nbsp;&nbsp;&nbsp;&nbsp;舱位:' + req.data[i].space + '</p>';
							htm += '<p>购票时间:' + req.data[i].buyTime + '</p>';
							htm += '</li>';
						}
						yidu.html(htm);
					}
				});
			}
			weidufun();
			yidufun();

		});
	</script>

</html>